var Api = require('../../../config/api.js');
const app = getApp();
Page({

  data: {
    userInfo: { "avatarUrl": '/image/icon/user-unlogin.png', 'nickName': '点击头像登陆认证' },
    logged: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    aboutUsUrl: Api.aboutUsUrl
  },

  onLoad: function (options) {
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              this.setData({
                avatarUrl: res.userInfo.avatarUrl,
                userInfo: res.userInfo
              });
              app.globalData.userInfo = res.userInfo;
            }
          })
        }
      }
    })

  },

  onGetUserInfo: function (e) {
    if (!this.logged && e.detail.userInfo) {
      this.setData({
        logged: true,
        avatarUrl: e.detail.userInfo.avatarUrl,
        userInfo: e.detail.userInfo
      })

      app.globalData.userInfo = e.detail.userInfo;
    }
  },

  onReady: function () {
  },
  onShow: function () {

  },

  onHide: function () {

  },

  onUnload: function () {

  },

  onReachBottom: function () {

  },

  onShareAppMessage: function () {

  }
})